package cn.gson.seventh;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 系统Spring工具
 * @author gson
 *
 */
public class App {

	private static ApplicationContext ctx;

	private App() {
	}

	/**
	 * 启动Spring
	 */
	public static synchronized void init() {
		if (ctx == null) {
			ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		}
	}

	public static <T> T getBean(Class<T> requiredType) {
		if (ctx == null) {
			init();
		}
		return ctx.getBean(requiredType);
	}
}
